/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Bean;

import Database.Koneksi;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author Yohanes Beny P
 */
public class Konsumen {

    private String nama_pengirim, almt_pengirim, nama_penerima, almt_penerima, no_resi, tlp_pengirim;
    private String id;

    public Konsumen() {
    }

    public Konsumen(String nama_pengirim, String almt_pengirim, String nama_penerima, String almt_penerima, String no_resi, String tlp_pengirim, String id) {
        this.nama_pengirim = nama_pengirim;
        this.almt_pengirim = almt_pengirim;
        this.nama_penerima = nama_penerima;
        this.almt_penerima = almt_penerima;
        this.no_resi = no_resi;
        this.tlp_pengirim = tlp_pengirim;
        this.id = id;
    }

    public ResultSet cariDataKonsumen(String noResi) throws SQLException {
        Connection con = Koneksi.open();
        Statement stat = con.createStatement();
        String in = "select * from KONSUMEN_T where NO_RESI='" + noResi + "'";
        ResultSet rs = stat.executeQuery(in);
        return rs;
    }

    public int generateID() throws SQLException {
        Connection con = Database.Koneksi.open();
        Statement st = con.createStatement();
        String sql = "select * from KONSUMEN_T";
        ResultSet rs = st.executeQuery(sql);
        int ID = 0;
        while (rs.next()) {
            ID = Integer.parseInt(rs.getString("ID_KONSUMEN"));
        }
        return ID + 1;
    }

    public void terimaKonsumen(Konsumen ksm) throws SQLException {
        Connection con = Koneksi.open();
        Statement stat = con.createStatement();
        String in = "insert into KONSUMEN_T(ID_KONSUMEN, NAMA_PENGIRIM, ALAMAT_PENGIRIM, N0_TELEPON_PENGIRIM, NAMA_PENERIMA, ALAMAT_PENERIMA, NO_RESI)"
                + "values('" + ksm.getId() + "','" + ksm.getNama_pengirim() + "','" + ksm.getAlmt_pengirim() + "','"
                + ksm.getTlp_pengirim() + "','" + ksm.getNama_penerima() + "','" + ksm.getAlmt_penerima() + "','"
                + ksm.getNo_resi() + "')";
        stat.executeUpdate(in);
    }

    public String getNama_pengirim() {
        return nama_pengirim;
    }

    public void setNama_pengirim(String nama_pengirim) {
        this.nama_pengirim = nama_pengirim;
    }

    public String getAlmt_pengirim() {
        return almt_pengirim;
    }

    public void setAlmt_pengirim(String almt_pengirim) {
        this.almt_pengirim = almt_pengirim;
    }

    public String getNama_penerima() {
        return nama_penerima;
    }

    public void setNama_penerima(String nama_penerima) {
        this.nama_penerima = nama_penerima;
    }

    public String getAlmt_penerima() {
        return almt_penerima;
    }

    public void setAlmt_penerima(String almt_penerima) {
        this.almt_penerima = almt_penerima;
    }

    public String getNo_resi() {
        return no_resi;
    }

    public void setNo_resi(String no_resi) {
        this.no_resi = no_resi;
    }

    public String getTlp_pengirim() {
        return tlp_pengirim;
    }

    public void setTlp_pengirim(String tlp_pengirim) {
        this.tlp_pengirim = tlp_pengirim;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
}
